package com.junjie.checkin.service;

import com.junjie.checkin.mapper.ActivityHistoryMapper;
import com.junjie.checkin.mapper.ActivityMapper;
import com.junjie.checkin.response.admin.BusinessDataResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class DashboardService {

    @Autowired
    private ActivityMapper activityMapper;
    @Autowired
    private ActivityHistoryMapper activityHistoryMapper;

    /**
     * 获取今日活动数据
     * @return
     */
    public BusinessDataResponse getTodayActivity(LocalDateTime begin, LocalDateTime end) {
        Map map = new HashMap();
        map.put("begin", begin);
        map.put("end", end);
        //获取今日活动数量
        Integer totalEffectiveActivityCount = activityMapper.countEffectiveByMap(map);
        //获取今日活动参与人数
        Integer totalStudentsCount = activityMapper.countStudentsByMap(map);
        //获取今日活动积分
        Integer totalPoint = activityHistoryMapper.contPointMap(map);
        //获取今日活动完成率
        Integer totalActivityCount = activityMapper.countByMap();
        Double completionRate = totalEffectiveActivityCount.doubleValue() / totalActivityCount.doubleValue();
        return BusinessDataResponse.builder()
                .todayActivities(totalEffectiveActivityCount)
                .participants(totalStudentsCount)
                .totalPoints(totalPoint)
                .completionRate(completionRate)
                .build();
    }
}
